using System;
using System.IO;
using Hive.Core.Common.Shell;

namespace Hive.Core.Model.Commands
{
    /// <summary>
    /// Gets the source of a package branch.
    /// </summary>
    public class GetSourcePackageBranchCommand : BasePackageBranchCommand
    {
        /// <summary>
        /// Gets or sets whether to build the package branch after getting the source.
        /// </summary>
        public bool Build { get; set; }

        /// <inheritdoc />
        protected override CommandExitCode ExecuteWithPackageBranch(IHiveManager hiveManager, IShell shell, IPackageBranch packageBranch)
        {
            packageBranch.GetSource(shell);

            PackageBranchUtils.GetMissingPackageBranchRecursively(packageBranch, RecursionMode.Dependencies, shell);

            if (Build)
                packageBranch.Build(shell);

            return CommandExitCode.Success;
        }
    }
}